package cn.xzc.job.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;

/**
 * @author xzc
 * @Classname TimerMethod
 * @Description 添加到本地【不涉及对外数据交换的】类方法上的注解
 * @Date 2024/2/17 14:50
 */
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface TimerMethod {
    /**
     * cron表达式
     */
    String cron() default "";

    /**
     * A time zone for which the cron expression will be resolved. By default, this attribute is the empty String (i.e. the server's local time zone will be used).
     * 设置定时任务所需要的时区，默认和为空的情况下使用的是本地机器所使用的时区【允许为空】 TimeZone.getDefault()
     * 解析cron表达式时需要使用
     */
    String zone() default "";

    /**
     * Execute the annotated method with a fixed period between the end of the last invocation and the start of the next.
     * {@link #timeUnit}.
     *
     * @return the delay 在上一次执行任务执行结束之后固定间隔触发下次任务的时间间隔
     */
    long fixedDelay() default -1;


    /**
     * Execute the annotated method with a fixed period between invocations.
     * {@link #timeUnit}.
     *
     * @return the period 在上一次执行任务执行开始之后固定间隔触发下次任务的时间间隔
     */
    long fixedRate() default -1;

    /**
     * Number of units of time to delay before the first execution of a
     * {@link #fixedRate} or {@link #fixedDelay} task.
     * <p>The time unit is milliseconds by default but can be overridden via
     * {@link #timeUnit}.
     *
     * @return the initial 第一次执行任务开始前的延迟时间
     */
    long initialDelay() default -1;


    /**
     * The {@link TimeUnit} to use for {@link #fixedDelay},  {@link #fixedRate},   {@link #initialDelay}, and
     * <p>Defaults to {@link TimeUnit#MILLISECONDS}.
     * <p>This attribute is ignored for {@linkplain #cron() cron expressions}
     *
     * @return the {@code TimeUnit} to use fixedDelay字段、fixedRate、initialDelay时间单位
     */
    TimeUnit timeUnit() default TimeUnit.MILLISECONDS;
}
